<Window x:Class="ScrumSprintMonitor.ConfigEditor.Views.PresentationConfigurationEditorView.PresentationConfigurationEditorWindow"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:local="clr-namespace:ScrumSprintMonitor.ConfigEditor"
		xmlns:converters="clr-namespace:ScrumSprintMonitor.ConfigEditor.Converters"
		xmlns:ConvertersLib="clr-namespace:ScrumSprintMonitor.UI.Wpf.Converters;assembly=ScrumSprintMonitor.UI.Wpf"
		Title="User Interface Configuration"
		Background="Gray"
		WindowStartupLocation="CenterOwner" ShowInTaskbar="False" Closed="OnWindowClosed" Width="600" MouseLeftButtonDown="OnWindowMouseLeftButtonDown">

	<Window.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="pack://application:,,,/ScrumSprintMonitor.UI.Wpf;component/Styles/FormResourceDictionary.xaml" />
			</ResourceDictionary.MergedDictionaries>

			<converters:PercentageValueConverter x:Key="PercentageValueConverter" />
			<ConvertersLib:ColorToBrushValueConverter x:Key="ColorToBrushValueConverter" />
			<ConvertersLib:RemainingWorkStatusTextValueConverter x:Key="RemainingWorkStatusTextValueConverter" />

			<local:XamlServiceLocator x:Key="serviceLocator" />
		</ResourceDictionary>
	</Window.Resources>

	<Window.Style>
		<StaticResource ResourceKey="DefaultChrome" />
	</Window.Style>

	<DockPanel DataContext="{Binding Path=PresentationConfigurationEditorViewModel, Source={StaticResource serviceLocator}}">
		<Grid DockPanel.Dock="Top">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto" />
				<ColumnDefinition />
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
			</Grid.RowDefinitions>

			<ContentControl Grid.Row="0" Grid.ColumnSpan="2" ContentTemplate="{StaticResource Separator}" Content="Remaining Work Status" IsTabStop="False" Focusable="False" />

			<DataGrid x:Name="dataGrid" Grid.Row="1" Grid.ColumnSpan="2" AutoGenerateColumns="False" ItemsSource="{Binding RemainingWorkStatusRatioUpperLimits}" ItemStringFormat="" GridLinesVisibility="All" Foreground="Black" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="False" BorderThickness="1" AlternationCount="1" AlternatingRowBackground="WhiteSmoke" VerticalGridLinesBrush="Gainsboro" HorizontalGridLinesBrush="Cornsilk" HorizontalContentAlignment="Left" HorizontalAlignment="Stretch" HeadersVisibility="None" SelectionMode="Single" EnableRowVirtualization="False" AreRowDetailsFrozen="True">
				<DataGrid.Columns>
					<DataGridTemplateColumn Header="Name" Width="Auto" IsReadOnly="True">
						<DataGridTemplateColumn.CellTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding Path=StatusPresentationConfig.Status, Mode=OneWay, Converter={StaticResource RemainingWorkStatusTextValueConverter}}" VerticalAlignment="Center" Margin="3" />
							</DataTemplate>
						</DataGridTemplateColumn.CellTemplate>
					</DataGridTemplateColumn>
					<DataGridTemplateColumn Header="Lower Limit" Width="Auto">
						<DataGridTemplateColumn.CellTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding Path=StatusPresentationConfig.LowerLimit, Converter={StaticResource PercentageValueConverter}}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3" />
							</DataTemplate>
						</DataGridTemplateColumn.CellTemplate>
						<DataGridTemplateColumn.CellEditingTemplate>
							<DataTemplate>
								<TextBox Text="{Binding Path=StatusPresentationConfig.LowerLimit, Converter={StaticResource PercentageValueConverter}}" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0" Padding="0" HorizontalContentAlignment="Stretch" TextAlignment="Right" IsReadOnly="{Binding Path=IsLowerLimitReadOnly}" Loaded="OnTextBoxLoaded" />
							</DataTemplate>
						</DataGridTemplateColumn.CellEditingTemplate>
					</DataGridTemplateColumn>
					<DataGridTemplateColumn Header="Upper Limit" Width="Auto">
						<DataGridTemplateColumn.CellTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding Path=StatusPresentationConfig.UpperLimit, Converter={StaticResource PercentageValueConverter}}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3" />
							</DataTemplate>
						</DataGridTemplateColumn.CellTemplate>
						<DataGridTemplateColumn.CellEditingTemplate>
							<DataTemplate>
								<TextBox Text="{Binding Path=StatusPresentationConfig.UpperLimit, Converter={StaticResource PercentageValueConverter}}" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0" Padding="0" HorizontalContentAlignment="Stretch" TextAlignment="Right" IsReadOnly="{Binding Path=IsUpperLimitReadOnly}" Loaded="OnTextBoxLoaded" />
							</DataTemplate>
						</DataGridTemplateColumn.CellEditingTemplate>
					</DataGridTemplateColumn>
					<DataGridTemplateColumn Header="Color" Width="80">
						<DataGridTemplateColumn.CellTemplate>
							<DataTemplate>
								<Border BorderThickness="3" HorizontalAlignment="Stretch" Background="{Binding Path=StatusPresentationConfig.BackgroundColor, Converter={StaticResource ColorToBrushValueConverter}}" Margin="1, 0" CornerRadius="0.25,4,0.25,4">
									<TextBlock Text="Text" Foreground="White" VerticalAlignment="Center" Margin="3" />
								</Border>
							</DataTemplate>
						</DataGridTemplateColumn.CellTemplate>
						<DataGridTemplateColumn.CellEditingTemplate>
							<DataTemplate>
								<ComboBox x:Name="comboBox" ItemsSource="{Binding Path=PresentationConfigurationEditorViewModel.Colors, Source={StaticResource serviceLocator}}" SelectedItem="{Binding StatusPresentationConfig.BackgroundColor}" IsDropDownOpen="True">
									<ComboBox.ItemsPanel>
										<ItemsPanelTemplate>
											<VirtualizingStackPanel />
										</ItemsPanelTemplate>
									</ComboBox.ItemsPanel>

									<ComboBox.ItemTemplate>
										<DataTemplate>
											<Border Background="{Binding Path=., Converter={StaticResource ColorToBrushValueConverter}}" Margin="1, 0" CornerRadius="0.25,4,0.25,4">
												<TextBlock Text="Text" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="3" />
											</Border>
										</DataTemplate>
									</ComboBox.ItemTemplate>
								</ComboBox>
							</DataTemplate>
						</DataGridTemplateColumn.CellEditingTemplate>
					</DataGridTemplateColumn>
				</DataGrid.Columns>
			</DataGrid>
		</Grid>

		<StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Bottom" Margin="0,12,0,0">
			<Button Command="{Binding OkCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Margin="6,0,0,0" Padding="16,4" MinWidth="72" IsDefault="True" Content="O_K" />
			<Button Command="{Binding CancelCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" x:Name="cancelButton" Margin="6,0,0,0" Padding="16,4" MinWidth="72" IsCancel="True" Content="Cancel" />
		</StackPanel>
	</DockPanel>
</Window>